<div class="modal fade" id="ajax_upload_mfile" tabindex="-1" role="dialog" aria-labelledby="ajax_upload_mfile">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form target="hidden_frame" action="<?php echo Common::RewriteUrl("AjaxUploadFile","roomupload");?>" enctype="multipart/form-data"  method="post">
                    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">文件上传</h4>
      </div>
                  <div class="modal-body">
                      <div class="jpbody">
                          <{if isset($imagelist)&&$imagelist}>
                          <{foreach $imagelist as $v}>
                           <div class="media">
  <div class="media-left">
      <img class="media-object txyl" src="<{$v["thumb"]}>" alt="">
  </div>
  <div class="media-body verticaltop">
    
 <input type="file" name="image[]" multiple="multiple" class="pull-left uploadfile" />
 <a class="btn btn-danger btn-xs pull-right deleteimage"  data-id="<{$v["id"]}>" href="javascript:void(0);"><span class="glyphicon glyphicon-trash"></span></a>
  
  </div>
</div>
                          <{/foreach}>
                          <{else}>
 <div class="media">
  <div class="media-left">
      <img class="media-object txyl" src="/images/thumb/100x100/nopic.png" alt="">
  </div>
  <div class="media-body verticaltop">
    
 <input type="file" name="image[]" multiple="multiple" class="pull-left uploadfile" />
 <a class="btn btn-danger btn-xs pull-right deleteimage"  data-id="11" href="javascript:void(0);"><span class="glyphicon glyphicon-trash"></span></a>
  
  </div>
</div>
                          <{/if}>
              </div>
                      <div>
                          
                          <a href="javascript:void(0);" id="uploadimageadd" class="btn btn-danger pull-right"><span class="glyphicon glyphicon-plus"></span></a>
                         <div class="clearfix"></div>
                      </div>
                 
                      
                </div>
       <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="submit" class="btn btn-primary">上传</button>
      </div>
            </form>
            <iframe name='hidden_frame' id="hidden_frame" style='display:none'></iframe>
        </div>
    </div>
</div>
<script>
    $("#uploadimageadd").click(function(){
        var obj=$(".media").eq(0);
        if(obj.length>0){
            var media=$(".media").eq(0).clone();
            media.find(".txyl").attr("src","/images/thumb/100x100/nopic.png");
           
           
        }else{
            media=$('<div class="media"><div class="media-left"><img class="media-object txyl" src="/images/thumb/100x100/nopic.png" alt=""></div><div class="media-body verticaltop"><input type="file" multiple="multiple" name="image[]" class="pull-left uploadfile" /><a class="btn btn-danger btn-xs pull-right deleteimage"  data-id="11" href="javascript:void(0);"><span class="glyphicon glyphicon-trash"></span></a></div></div>');
        }
            $(".jpbody").append(media);
            var top=$(this).position().top;
            $("#ajax_upload_mfile").scrollTop(top);
            media.find(".deleteimage").bind("click",deleteimage);
            media.find(".uploadfile").bind("change",uploadchange);
    });
    $(".deleteimage").click(deleteimage);
    function deleteimage(){
        var id=$(this).data("id");
        //执行逻辑
        
        if(id>0){
            var url="<{echo Common::RewriteUrl("AjaxUploadFile","public_ajax_deleteroompic");}>";
            $.post(url,{"id":id},function(){
               
            });
        }
        
       //执行逻辑
       $(this).parent().parent().remove();
       var deleteimage=$(".deleteimage");
       var ids=new Array();
       for(var i=0;i<deleteimage.length;i++){
            ids.push(deleteimage.eq(i).data("id"));
        }
        $("input[name='imageids']").val(ids.join());
    }
    function ajax_upload_callback(data){
        $("input[name='imageids']").val("");
        var deleteimage=$(".deleteimage");
        $("input[name='imageids']").val(data.join());
        for(var i=0;i<deleteimage.length;i++){
            deleteimage.eq(i).data("id",data[i]);
        }
        $("#ajax_upload_mfile").modal('hide');
        
    }
    function uploadchange(){
        var upload=$(this).get(0);
        var preview=$(this).parent().parent().find(".txyl").get(0);
      
        setImagePreview(upload,preview);
    }
    $(document).ready(function(){
        $(".uploadfile").change(uploadchange);
    });
    
    function setImagePreview(upload,preview) {
    
       
        var docObj=upload;
        var imgObjPreview=preview;
        if(docObj.files &&    docObj.files[0]){
            //火狐下，直接设img属性
            imgObjPreview.style.display = 'block';
            imgObjPreview.style.width = '100px';
            imgObjPreview.style.height = '100px';
            try{
                imgObjPreview.src = docObj.files[0].getAsDataURL();
            }catch(e){
                //火狐7以上版本不能用上面的getAsDataURL()方式获取，需要一下方式
                imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]);
            }
 
 
        }else{
            //IE下，使用滤镜
            docObj.select();
            var imgSrc = document.selection.createRange().text;
            var localImagId = document.getElementById("localImag");
            //必须设置初始大小
            localImagId.style.width = "160px";
            localImagId.style.height = "120px";
            //图片异常的捕捉，防止用户修改后缀来伪造图片
            try{
                localImagId.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
                localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
            }catch(e){
                alert("您上传的图片格式不正确，请重新选择!");
                return false;
            }
            imgObjPreview.style.display = 'none';
            document.selection.empty();
        }
        return true;
    
 
}
</script>